				<extend name="Public/content" />
<block name="style">
<style type="text/css">
    .table>tbody>tr>td{ padding: 4px; vertical-align: middle;}
        body{ background: #fff;}
           .footer {
    width: 100%;
    height: 50px;
    position: fixed;
    bottom: 0;
   
    left: 0;
    line-height: 50px;
    text-align: right;
    text-align: right;
    border-top: solid 1px #eee;
    padding-right: 10px;
    z-index: 999999999999999;
}
.checkbox {
    display: inline-block;
     width: 24%;
}
.row_gc{ width: 100% !important;}
.col-xs-12ga_c{ padding: 20px 0 20px 30px;}
.blue_gaik{ width: 100%;}
.lbl_gc::before{margin-right: 6px;}
</style>
</block>
<block name="body">


    <include file="Public:artdialog" />
    <div class="row row_gc">
               <div class="col-xs-12 col-xs-12ga_c">
                   <volist name="list" id="vo">
                                      <label class="control-label bolder blue blue_gaik">{$vo.brand_type_name}</label>
                                      <volist name="vo.lists" id="v"> 
                                           <span class=" ">
                                                <div class="checkbox">
                                                    <label>
                                                        <input name="form-field-checkbox" field='"brand_id":"{$v.brand_id}","brand_name":"{$v.brand_name}"' class="ace ace-checkbox-2" value="{$v.brand_id}" type="checkbox">
                                                        <span class="lbl lbl_gc">{$v.brand_name}</span>
                                                    </label>
                                                </div>
                                            </span>
                                      </volist>
                                      <hr>
                   </volist>
              </div>
        </div><!--/col-md-12-->

</block>
<block name="script">
 <script type="text/javascript">
//定义cookiename
var cookiename="brand_<?php echo UID; ?>";

$(function(){ 
  _hide_public_loading();
     $('input[type="checkbox"]').bind("click",setgoodincookie);
     listinit();//初始化页面 
 }); 
     
 //初始化页面设置存在选中的商品信息
 function listinit(){
     var _list=getCookie(cookiename);
     if(_list==""){return;}
     var ojson=JSON.parse(_list);
     $('input[type="checkbox"]').each(function(){
        var tmp= $(this).val();
        var _isflg=isExist(ojson,tmp);
        if(_isflg){
            $(this).prop("checked",_isflg);
        }
     }); 
 }
 
 
 //判断json数据中是否存在商品编号id
 function isExist(ary,val){

      var flg=false;
      if(ary==null || ary.length==0)return flg;
      for(var i=0;i<ary.length;i++){
          if(ary[i]['brand_id']==val){
              flg=true;
              break;
          }
      }
      return flg;
 }
 
 
 //勾选时执行数据的清理以及写入
 function setgoodincookie()
 {
    var flg= $(this).is(":checked");
    var _json=[],ojson=[],json=[];   
    var _tmv="{"+$(this).attr("field")+"}";
    var _json=JSON.parse(_tmv); 
    if(!_json)return;
    
    //获取cookie值
    var _list=getCookie(cookiename);
    if(_list !=null && _list!="" ){
      ojson=JSON.parse(_list);
    } 
    //从cookie中获取的值哪些需要删除，哪些需要更新 
    for(var i=0;i<ojson.length;i++){ 
        //相等处理
        if(ojson[i]['brand_id']==_json['brand_id']){ 
           if(flg){json.push(_json);}  //勾选，就更新这个记录
        }else{
          json.push(ojson[i]);  //不相等添加
        }
    } 
    var bl=isExist(ojson,_json['brand_id']);
    //如果是勾选并且是不存在cookie记录新时，增加
    if(!bl && flg){json.push(_json);}
    //考虑重复记录的清理。 
    setCookie(cookiename,"",-10);
     if(json.length>0){
        var _db=JSON.stringify(json);
        setCookie(cookiename,_db,1);
     } 
 }  
 
//写入cookie
 function setCookie(c_name, value, expiredays){
    if(expiredays < 0){
        localStorage.removeItem(c_name);
    }
       localStorage.setItem(c_name,value); //存储名字为name值为caibin的变量
 }
//读取cookie   
 function getCookie(c_name){
    return  localStorage.getItem(c_name);
 }

 </script>
</block>
